package com.ythook.mentor.controller;

import com.ythook.mentor.entity.MentorSkills;
import com.ythook.mentor.entity.Technologies;
import com.ythook.mentor.service.MentorSkillsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/api")
public class MentorSkillsController {
    @Resource
    private MentorSkillsService mentorSkillsService;
    private Logger logger = LoggerFactory.getLogger(MentorSkillsController.class);

    @GetMapping("/skills")
    public ResponseEntity<List<MentorSkills>> search() {
        return ResponseEntity.ok(mentorSkillsService.search());
    }
    @GetMapping("/skills/findById/{id}")
    public ResponseEntity<MentorSkills> findById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(mentorSkillsService.findById(id).orElse(new MentorSkills()));
    }

    @GetMapping("/skills/findByMentorId/{id}")
    public ResponseEntity<List<Optional<Technologies>>> findByMentorId(@PathVariable("id") Long id) {
        return ResponseEntity.ok(mentorSkillsService.findByMentorId(id));
    }

    @DeleteMapping("/skills/delete/{id}")
    public ResponseEntity<Object> delete(@PathVariable("id") Long id){
        mentorSkillsService.delete(id);
        Map<String,Object> map = new HashMap<>();
        map.put("status","success");
        return ResponseEntity.ok(map);
    }

    @DeleteMapping("/skills/deleteByTechId/{mentorId}/{techId}")
    public ResponseEntity<Object> deleteByTechId(@PathVariable("mentorId") Long mentorId, @PathVariable("techId") Long techId){
        mentorSkillsService.deleteByTechId(mentorId, techId);
        Map<String,Object> map = new HashMap<>();
        map.put("status","success");
        return ResponseEntity.ok(map);
    }

    @PostMapping("/skills/add")
    public ResponseEntity<HttpStatus> add(@RequestBody MentorSkills mentorSkills){
        mentorSkillsService.add(mentorSkills);
        return ResponseEntity.ok(HttpStatus.CREATED);
    }
    @PostMapping("/skills/multiAdd")
    public ResponseEntity<HttpStatus> multiAdd(@RequestBody List<MentorSkills> mentorSkillsList){
        mentorSkillsService.multiAdd(mentorSkillsList);
        return ResponseEntity.ok(HttpStatus.CREATED);
    }
}
